<?php
class model_note extends common_model {
	/**
	 * 基本表属性
	 */
	protected $table = 'notes';
	protected $pk = 'not_id';
	/**
	 * 查询结果数
	 * @var int
	 */
	private $_query_count = 0;
	
	/**
	 * 每天记事
	 * @return array
	 */
	public function daily_notes($where = 1) {
		//原始数据
		$res = $this->find_all($where, 'create_time DESC');
		//初始化
		$daily_notes = array();
		//query_conut
		$this->_query_count = count($res);
		
		foreach ($res as $row) {
			$key = library_common::str2date(date('Y-m-d', $row['create_time']));
			$daily_notes[$key][] = $row;
		}
		
		return $daily_notes;
	}
	
	/**
	 * 获取记事
	 * @param string $where
	 * @return array
	 */
	public function get_notes($where) {
		$res = $this->find_all($where);
		return $res;
	}
	
	/**
	 * 获取查询结果数
	 * @return int
	 */
	public function get_query_count() {
		return $this->_query_count;
	}
	
	/**
	 * 记事总数
	 * @param string $where 条件
	 * @return int
	 */
	public function count($where = 1) {
		$res = $this->find_all($where, '', '', 'COUNT(*) res_count');
		return $res[0]['res_count'];
	}
	
	/**
	 * 设置rank
	 * @param int $not_id 记事ID
	 * @param int $rank 级别
	 */
	public function rank_set($not_id, $rank) {
		$data = array();
		$data['not_id'] = $not_id;
		$data['rank'] = $rank;
		
		$this->update($data);
	}
}
?>
